package com.igeek.service.impl;



import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.igeek.mapper.BankAccountMapper;

import com.igeek.model.insurance.BankAccount;
import com.igeek.model.insurance.Insurance;
import com.igeek.service.IBankAccountService;
import com.igeek.service.IInsuranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-23
 */
@Service
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements IBankAccountService {
    @Autowired
    private IInsuranceService iInsuranceService;

    @Override
    public void account(BankAccount bankAccount, Integer id) {
        Insurance insurance=iInsuranceService.getById(id);
        if(insurance.getIncome().equals(bankAccount.getIncome())&&
                insurance.getExpenditure().equals(bankAccount.getExpenditure())&&
                insurance.getMonth().equals(bankAccount.getDate()) ){
            bankAccount.setStatus("已对账");
            bankAccount.setTransactionId(id);
            bankAccount.setType("无");
            bankAccount.setDate(bankAccount.getDate());
            bankAccount.setExpenditure(bankAccount.getExpenditure());
            bankAccount.setIncome(bankAccount.getIncome());
            bankAccount.setId(id);
            this.baseMapper.updateById(bankAccount);
        }else if(bankAccount.getIncome()==null||bankAccount.getExpenditure()==null||bankAccount.getDate()==null){
            bankAccount.setStatus("未对账");
            bankAccount.setTransactionId(id);
            bankAccount.setType("未记录交易");
            bankAccount.setId(id);
            this.baseMapper.updateById(bankAccount);
        }else if(!(insurance.getIncome().equals(bankAccount.getIncome())&&insurance.getExpenditure().equals(bankAccount.getExpenditure()))&&
        insurance.getMonth().equals(bankAccount.getDate())){
            bankAccount.setStatus("未对账");
            bankAccount.setTransactionId(id);
            bankAccount.setType("金额差异");
            bankAccount.setId(id);
            this.baseMapper.updateById(bankAccount);
        }else if(!(insurance.getMonth().equals(bankAccount.getDate()))&&insurance.getIncome().equals(bankAccount.getIncome())&&
         insurance.getExpenditure().equals(bankAccount.getExpenditure())){
            bankAccount.setStatus("未对账");
            bankAccount.setTransactionId(id);
            bankAccount.setType("时间差异");
            bankAccount.setId(id);
            this.baseMapper.updateById(bankAccount);
        }else if(insurance.getId().equals(bankAccount.getTransactionId())){
            bankAccount.setStatus("未对账");
            bankAccount.setTransactionId(id);
            bankAccount.setType("重复记录");
            bankAccount.setId(id);
            this.baseMapper.updateById(bankAccount);
        }


    }
}
